package model

import (
	"log"
	"xorm.io/xorm"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-redis/redis/v8"
	"github.com/eeppee_admin/clouddisk/service/internal/config"
)

// var XormEngine = Init()

// Init MySql
func Init(dsn string) *xorm.Engine {
	// dsn := "root:123456@tcp(127.0.0.1:3306)/clouddiskdb?charset=utf8mb4&parseTime=True&loc=Local"
	engine, err := xorm.NewEngine("mysql", dsn)
	if err != nil {
		log.Printf("Xorm New Engine: %v\n", err)
		return nil
	}

	return engine
}

// Init Redis
func InitRedis(c config.Config) *redis.Client {
	return redis.NewClient(&redis.Options{
		Addr: c.Redis.Addr,
		Password: "", // no password
		DB: 0, // default DB
	})
}